package example.bookservlet;

import example.entity.Book;
import example.service.BookService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 更新图书的Servlet
 *
 * @author 张心怡
 * @date 2024/12/16
 */
@WebServlet("/updateBookServlet")
public class UpdateBookServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int id = Integer.parseInt(request.getParameter("id"));
        String name = request.getParameter("name");
        String author = request.getParameter("author");
        float score = Float.parseFloat(request.getParameter("score"));
        int count = Integer.parseInt(request.getParameter("count"));
        String ISBN = request.getParameter("ISBN");
        String category = request.getParameter("category");

        Book book = new Book();
        book.setId(id);
        book.setName(name);
        book.setAuthor(author);
        book.setScore(score);
        book.setCount(count);
        book.setISBN(ISBN);
        book.setCategory(category);

        BookService.updateBook(book);

        response.sendRedirect("listBooksServlet");
    }
}
